<?php
// Version
define('VERSION', '1.0.0.0');

// Configuration
require_once('config.php');

// Startup
require_once(DIR_KERNEL . 'startup.php');

// Application Classes
require_once(DIR_KERNEL . 'library/member.php');

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Config
$config = new Config();
$registry->set('config', $config);

$config->set('config_url', HTTP_SERVER);
$config->set('config_ssl', HTTPS_SERVER);

// Url
$url = new Url($config->get('config_url'), $config->get('config_use_ssl') ? $config->get('config_ssl') : $config->get('config_url'));
$registry->set('url', $url);

$log = new Log('log.log');
$registry->set('log', $log);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

// Request
$request = new Request();
$registry->set('request', $request);

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression(CONF_SYS_COMPRESSION);
$registry->set('response', $response);

// Cache
$cache = new Cache();
$registry->set('cache', $cache); 

// Session
$session = new Session();
$registry->set('session', $session); 

//Zone
$clientIp = isset($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$clientIp = ($clientIp) ? $clientIp : $_SERVER["REMOTE_ADDR"];
$clientZone = array('city_id'=>350100);
$registry->set('client_zone', $clientZone); //convertip_full('110.83.21.0'));

// Document
$registry->set('document', new Document());

// Result
$registry->set('result', new Result($registry));

// Customer
$registry->set('member', new Member($registry));
		
// Front Controller 
$controller = new Front($registry);


// Maintenance Mode
//$controller->addPreAction(new Action('common/maintenance'));	

// SEO URL's
 $controller->addPreAction(new Action('common/seo_url'));

// Router
if (isset($request->get['route'])) {
	$action = new Action($request->get['route']);
} else {
	$action = new Action('common/home');
}
// Dispatch
$controller->dispatch($action, new Action('error/not_found'));

// Output
$response->output();
?>